package architect.design.patterns.creation.singleton;

import java.io.Serializable;

/**
 * 序列化单例
 *
 * @author guanxin
 * @date 2018/5/4 10:51
 */

public class SerializableSingleton implements Serializable {
    private static final long serialVersionUID = -7604766932017737115L;

    private static class LazyHolder{
        private static final SerializableSingleton INSTANCE = new SerializableSingleton();
    }

    public static SerializableSingleton getInstance(){
        return LazyHolder.INSTANCE;
    }

    // 确保反序列化单例
    protected Object readResolve() {
        return getInstance();
    }
}
